public class Solution {
    public List<String> binaryTreePathsOp(TreeNode root) {
        List<String> list = new ArrayList<>();
        if(root == null) {
            return list;
        }
        if(root.left == null && root.right == null) {
            list.add(root.val + "->");
            return list;
        }
        if(root.left != null) {
            list.addAll(binaryTreePathsOp(root.left));
        }
        if(root.right != null) {
            list.addAll(binaryTreePathsOp(root.right));
        }
        for(int i = 0; i < list.size(); i++) {
            list.set(i, root.val + "->" + list.get(i));
        }
        return list;
    }

    public List<String> binaryTreePaths(TreeNode root) {
        List<String> list = binaryTreePathsOp(root);
        return list.stream().map(s -> s.substring(0, s.length() - 2)).collect(Collectors.toList());
    }
}